package top.stmo.springMvcDemo.controller;


import org.springframework.web.bind.annotation.*;
import top.stmo.springMvcDemo.pojo.Books;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {

    @PostMapping
    public String save(@RequestBody Books books) {
        System.out.println("book save" + books);
        return "book save ----" + books;
    }



    @GetMapping("/{id}")
    public Books getById(@PathVariable Integer id) {
        Books books = new Books();
        books.setId(id);
        books.setType("计算机");
        books.setName("getById");
        books.setDescription("小试牛刀");
        return books;
    }

    @GetMapping
    public List<Books> getAll() {

        List<Books> bookList = new ArrayList<Books>();
        Books book1 = new Books();
        book1.setType("计算机");
        book1.setName("SpringMVC入门教程");
        book1.setDescription("小试牛刀");
        bookList.add(book1);
        Books book2 = new Books();
        book2.setType("计算机");
        book2.setName("SpringMVC实战教程");
        book2.setDescription("一代宗师");
        bookList.add(book2);
        Books book3 = new Books();
        book3.setType("计算机丛书");
        book3.setName("SpringMVC实战教程进阶");
        book3.setDescription("一代宗师呕心创作");
        bookList.add(book3);

        return bookList;
    }

    @DeleteMapping("/{id}")
    public Books delete(@PathVariable Integer id) {

        Books books = new Books();
        books.setId(id);
        books.setType("计算机");
        books.setName("delete");
        books.setDescription("小试牛刀");
        return books;
    }


}
